#include "AddressDialog.h"

AddressDialog::AddressDialog(QWidget* parent)
    : QDialog(parent)
    , title_label(new QLabel("服务器地址", this))
    , ip_input(new QLineEdit("cn-zz-bgp-4.natfrp.cloud", this))
    , port_input(new QLineEdit("62366", this))
    , ok_button(new QPushButton("确定", this))
    , cancel_button(new QPushButton("取消", this))
    , form(new QFormLayout)
    , button_layout(new QHBoxLayout)
    , widget_layout(new QVBoxLayout(this))
{
    setWindowTitle(title_label->text());
    title_label->setAlignment(Qt::AlignCenter);

    form->addRow("IP", ip_input);
    form->addRow("端口", port_input);

    button_layout->addWidget(ok_button);
    button_layout->addWidget(cancel_button);

    widget_layout->addWidget(title_label);
    widget_layout->addLayout(form);
    widget_layout->addLayout(button_layout);

    connect(ok_button, SIGNAL(clicked()), this, SLOT(accept()));
    connect(cancel_button, SIGNAL(clicked()), this, SLOT(reject()));
}
QPair<QString, int> AddressDialog::getAddress()
{
    return { ip_input->text(), port_input->text().toInt() };
}
